//#include "catch.hpp"

#include "http/server.h"
#include "common/log.h"


int main(int argc, char **argv) {
    using namespace evm;
    using namespace evm::http;

    init_log("http_tests", false, true);

    string host = "127.0.0.1";
    uint16_t port = 9000;
    size_t concurrency = 2;
    HTTPServer http_server(host, port, concurrency);
    Router &router = http_server.router();

    router("/path/to/dest")
            ([](const Request &req) -> Response {
                Response rep;
                LOG->info() << req.str();
                rep.write("very good; ");
                rep.write("very bad.");
                return rep;
    });

    router("/path/to/haha")
            ([](const Request &req) -> Response {
                LOG->info() << req.str();
                Json j = {
                        {"pi", 3.141},
                        {"happy", true},
                        {"name", "Niels"},
                        {"nothing", nullptr},
                        {"answer", {
                                           {"everything", 42}
                                   }
                        },
                        {"list", {1, 0, 2}},
                        {"object", {
                                           {"currency", "USD"},
                                           {"value", 42.99}
                                   }
                        }
                };
                return Response(j);
            });

    router("/path/to/post", POST)
            ([](Request &req) -> Response {
                if (req.has_file) {
                    req.file_name = "recvfile";
                    req.file_handler = [] {
                        INFO("received");
                    };
                    return Response();
                }
                else
                    return Response::bad_request("no file");
            });

    router("/path/to/get", POST)
            ([](const Request &req) -> Response {
                return Response::recv_file(200, "lvm.py");
            });

    router("/<tenant:str>/servers/<server:int>", POST)
            ([](const Request &req) -> Response {
                LOG->info() << "in handle:" << req.str();
                return Response();
            });

    http_server.start();
    return 0;
}
